import java.util.Arrays;

public class project {
    public int countKDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int count=0;
        int len=nums.length;
        for(int i=0;i<len-1;i++){
            for(int j=i+1;j<len;j++){
                if(nums[j]-nums[i]==k){
                    count++;
                }else if(nums[j]-nums[i]>k){
                    break;
                }
            }
        }
        return count;
    }











    public int countKDifference1(int[] nums, int k) {
        int len=nums.length;
        int count=0;
        for(int i=0;i<len-1;i++){
            for(int j=i+1;j<len;j++){
                if(Math.abs(nums[i]-nums[j])==k){
                    count++;
                }
            }
        }
        return count;
    }
}
